package com.tuanbiao.models.action;

import androidx.annotation.NonNull;

import com.hzjq.data.entity.PlanEntity;
import com.hzjq.lib.BlastKool;
import com.hzjq.lib.callback.ResultCallback;
import com.tuanbiao.data.callback.OnBaseResultCallback;

import java.util.List;

/**
 * @author abiao
 * @since 2022/4/20 14:58
 */
public interface PlanAction {

    default void refreshPlan(OnBaseResultCallback<List<PlanEntity>> callback) {
        BlastKool.Companion.loader().db().refreshPlan(entities -> {
            callback.onSuccess(entities);
            callback.onFinish();
        });
    }

    default void getPlanList(OnBaseResultCallback<List<PlanEntity>> callback) {
        BlastKool.Companion.loader().db().queryPlan(entities -> {
            callback.onSuccess(entities);
            callback.onFinish();
        });
    }

    default void insertPlan(PlanEntity plan, OnBaseResultCallback<Void> callback) {
        BlastKool.Companion.loader().db().insertPlan(plan, () -> {
            callback.onSuccess(null);
            callback.onFinish();
        });
    }

    default void updatePlan(PlanEntity plan, OnBaseResultCallback<Void> callback) {
        BlastKool.Companion.loader().db().updatePlan(plan, () -> {
            callback.onSuccess(null);
            callback.onFinish();
        });
    }

    default void selectPlan(boolean select, OnBaseResultCallback<Void> callback) {
        BlastKool.Companion.loader().db().selectAllPlan(select, () -> {
            callback.onSuccess(null);
            callback.onFinish();
        });
    }

    default void deletePlan(PlanEntity plan, OnBaseResultCallback<Void> callback) {
        BlastKool.Companion.loader().db().deletePlan(plan, () -> {
            callback.onSuccess(null);
            callback.onFinish();
        });
    }

    default void deletePlan(List<PlanEntity> plans, OnBaseResultCallback<Void> callback) {
        BlastKool.Companion.loader().db().deletePlans(plans, () -> {
            callback.onSuccess(null);
            callback.onFinish();
        });
    }

    default void copyPlan(String srcPlanId, String toPlanName, OnBaseResultCallback<Boolean> callback) {
        BlastKool.Companion.loader().db().copyPlan(srcPlanId, toPlanName, aBoolean -> {
            callback.onSuccess(aBoolean);
            callback.onFinish();
        });
    }

    default void mergePlan(String newPlanName, List<PlanEntity> entities, OnBaseResultCallback<Boolean> callback) {
        BlastKool.Companion.loader().db().mergePlan(newPlanName, entities, new ResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean aBoolean) {
                callback.onSuccess(aBoolean);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }
}
